package com.wss.module.wan.ui.series.mvp;

import com.wss.common.base.mvp.BasePresenter;
import com.wss.common.utils.ValidUtils;
import com.wss.module.wan.bean.Classification;
import com.wss.module.wan.ui.series.mvp.contract.SeriesContract;
import com.wss.module.wan.ui.series.mvp.model.SeriesModel;
import com.zhouyou.http.callback.SimpleCallBack;
import com.zhouyou.http.exception.ApiException;

import java.util.List;

/**
 * Describe：体系Presenter
 * Created by 吴天强 on 2018/11/21.
 */
public class SeriesPresenter extends BasePresenter<SeriesModel, SeriesContract.View>
        implements SeriesContract.Presenter {


    @Override
    protected SeriesModel createModule() {
        return new SeriesModel(getLifecycleOwner());
    }

    @Override
    public void start() {
        showLoading();
        getModel().getSystem(new SimpleCallBack<List<Classification>>() {
            @Override
            public void onError(ApiException e) {
                getView().onError("", e.getMessage());
            }

            @Override
            public void onSuccess(List<Classification> classification) {
                dismissLoading();
                if (ValidUtils.isValid(classification)) {
                    getView().refreshSystemList(classification);
                } else {
                    getView().onEmpty("");
                }
            }
        });
    }
}
